package com.itheima.web;

import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import com.itheima.support.PageResult;
import com.itheima.support.QueryPageBean;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @DubboReference
    private CheckItemService checkItemService;

    /***
     * 添加用户
     * @param checkItem
     * @return
     */
    @PostMapping("/add")
    public boolean add(@RequestBody CheckItem checkItem){
        System.out.println("checkItemService.save");
        return  checkItemService.save(checkItem);
    }

    /***
     * 新增或者修改可以使用改方法
     * @param checkItem
     * @return
     */
    @PostMapping("/save")
    @PreAuthorize("hasAuthority('save_checkitem')")
    public boolean save(@RequestBody CheckItem checkItem){
        return checkItemService.saveOrUpdate(checkItem);
    }

    /**
     * 查询所有用户
     * @return
     */
    @GetMapping("/findAll")
    public List<CheckItem>findAll(){
        return checkItemService.list();
    }

    /**
     * 分页查询
     * @param pageBean
     * @return
     */
    @PostMapping("/findByPage")
    @PreAuthorize("hasAuthority('search_checkitem')")
    public PageResult findByPage(@RequestBody QueryPageBean pageBean){
        return checkItemService.findByPage(pageBean);
    }

    /**
     * 逻辑删除
     * @param id
     * @return
     */
    @GetMapping("/deleteById/{id}")
    @PreAuthorize("hasAuthority('del_checkitem')")
    public boolean deleteById(@PathVariable("id") Long id){
        return checkItemService.removeById(id);
    }




}
